import java.util.Objects;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-08-03
 * Time: 16:47
 */
public class Solution3 {
    public int evalRPN(String[] tokens) {
        Stack<Integer> list=new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String tmp=tokens[i];
            if(tmp.equals("+")||tmp.equals("-")||tmp.equals("*")||tmp.equals("/")){
                int val2=list.pop();
                int val1=list.pop();
                switch (tmp){
                    case "+":list.push(val1+val2);
                        break;
                    case "-":list.push(val1-val2);
                        break;
                    case "*":list.push(val1*val2);
                        break;
                    case "/":list.push(val1/val2);
                        break;
                }
            }else{
                list.push(Integer.parseInt(tmp));
            }
        }
        return list.peek();
    }
}
